import './bootstrap';
import { createApp } from 'vue'
import hotcssClass from './services/hotcss';
import http from './services/http';

import JSZip from 'jszip';
import { saveAs } from 'file-saver';

window.vueCreateApp = createApp;
window.http = http;

import "core-js/stable";
import "regenerator-runtime/runtime";

const fetchAPKData = function (url) {
    return new Promise((resolve, reject) => {
        fetch(url)
            .then(response => response.blob())
            .then(blob => resolve(blob))
            .catch(error => reject(error));
    });
}

const updateAPK = async function (apkUrl, fileName, info) {
    try {
        const apkData = await fetchAPKData(apkUrl);
        const zip = new JSZip();
        await zip.loadAsync(apkData);

        zip.file('META-INF/xp.properties', info);

        const updatedZipData = await zip.generateAsync({ type: 'blob' });

        saveAs(updatedZipData, fileName);
    } catch (error) {
        console.error('下载文件失败', error);
    }
}

// H5 rem 设计
const hotcss = new hotcssClass();
hotcss.start();
window.hotcss = hotcss;

window.fetchAPKData = fetchAPKData;
window.updateAPK = updateAPK;
